home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 May / com_0505_1.iso / opensource / top10 / amc_install.exe / {app} / Scripts / Moviecovers (FR).ifs < prev    next >
Encoding:
Text File  |  2004-03-20  |  5.9 KB  |  174 lines

  1. // GETINFO SCRIPTING
  2. // Moviecovers (FR) import
  3.  
  4. (***************************************************
  5.  *  Movie importation script for:                  *
  6.  *      Moviecovers, http://www.moviecovers.com    *
  7.  *                                                 *
  8.  *  (c) 2003 Antoine Potten    software@antp.be    *
  9.  *                                                 *
  10.  *  For use with Ant Movie Catalog 3.4.2           *
  11.  *  www.antp.be/software/moviecatalog              *
  12.  *                                                 *
  13.  *  This program is free software; you can         *
  14.  *  redistribute it and/or modify it under the     *
  15.  *  terms of the GNU General Public License as     *
  16.  *  published by the Free Software Foundation;     *
  17.  *  either version 2 of the License, or (at your   *
  18.  *  option) any later version.                     *
  19.  ***************************************************)
  20.  
  21. program MovieCovers;
  22.  
  23. const
  24.   LargePicture = False; // set it to True to import large picture
  25.  
  26. var
  27.   MovieName: string;
  28.   LineNr: Integer;
  29.  
  30. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  31. var
  32.   i: Integer;
  33. begin
  34.   result := -1;
  35.   if StartAt < 0 then
  36.     StartAt := 0;
  37.   for i := StartAt to List.Count-1 do
  38.     if Pos(Pattern, List.GetString(i)) <> 0 then
  39.     begin
  40.       result := i;
  41.       Break;
  42.     end;
  43. end;
  44.  
  45. procedure AnalyzePage(Address: string);
  46. var
  47.   Line, Value: string;
  48.   LastLine, BeginPos, EndPos: Integer;
  49.   Page: TStringList;
  50. begin
  51.   Line := GetPage(Address);
  52.   if Pos('il n''y a pas de film correspondant à ce(s) critère(s) dans <B>MOVIECOVERS</B>', Line) > 0 then
  53.   begin
  54.     ShowMessage('No movie found');
  55.     Exit;
  56.   end;
  57.   PickTreeClear;
  58.   BeginPos := Pos('<FONT size="+1" color="#000000"><B>', Line);
  59.   Delete(Line, 1, BeginPos - 1);
  60.   EndPos := Pos('</FONT>', Line);
  61.   Value := Copy(Line, 1, EndPos - 1);
  62.   HTMLRemoveTags(Value);
  63.   HTMLDecode(Value);
  64.   BeginPos := Pos(' <TABLE border=0 cellspacing=0 cellpadding=6 align="center" width="100%">', Line) + 1;
  65.   Delete(Line, 1, BeginPos);
  66.   EndPos := Pos(' <TABLE border=0 cellspacing=0 cellpadding=6 align="center" width="100%">', Line) + 1;
  67.   Delete(Line, EndPos, Length(Line));
  68.   Page := TStringList.Create;
  69.   Page.Text := Line;
  70.   Value := Trim(Value) + ' : ' + Trim(Page.GetString(2));
  71.   PickTreeAdd(Value, '');
  72.   for LineNr := 3 to Page.Count-1 do
  73.   begin
  74.     Line := Page.GetString(LineNr);
  75.     if Pos('<LI><A', Line) > 0 then
  76.     begin
  77.       BeginPos := Pos('/film/titre', Line);
  78.       EndPos := Pos('">', Line);
  79.       Value := 'http://www.moviecovers.com' + Copy(Line, BeginPos, EndPos - BeginPos);
  80.       HTMLRemoveTags(Line);
  81.       PickTreeAdd(Trim(Line), Value);
  82.     end;
  83.   end;
  84.   if PickTreeExec(Address) then
  85.     AnalyzeMoviePage(Address);
  86.   Page.Free;
  87. end;
  88.  
  89. function TwoLinesAfter(Pattern: string; Page: TStringList): string;
  90. begin
  91.   LineNr := FindLine(Pattern, Page, LineNr);
  92.   Result := Page.GetString(LineNr+2);
  93.   HTMLRemoveTags(Result);
  94.   HTMLDecode(Result);
  95.   Result := Trim(Result);
  96. end;
  97.  
  98. procedure AnalyzeMoviePage(Address: string);
  99. var
  100.   Line, Value: string;
  101.   BeginPos, EndPos, IntValue: Integer;
  102.   Page: TStringList;
  103. begin
  104.   SetField(fieldURL, Address);
  105.   Page := TStringList.Create;
  106.   Page.Text := GetPage(Address);
  107.   LineNr := FindLine('<FONT color="#000000" size="+2">', Page, 0);
  108.   if LineNr > -1 then
  109.   begin
  110.     Line := Page.GetString(LineNr);
  111.     HTMLRemoveTags(Line);
  112.     SetField(fieldTranslatedTitle, Line);
  113.   end;
  114.   SetField(fieldOriginalTitle, TwoLinesAfter('<TH align="right" valign="top">Titre original</TH>', Page));
  115.   if GetField(fieldOriginalTitle) = '' then
  116.     SetField(fieldOriginalTitle, GetField(fieldTranslatedTitle));
  117.   SetField(fieldDirector, TwoLinesAfter('<TH align="right" valign="top">Réalisateur</TH>', Page));
  118.   SetField(fieldYear, TwoLinesAfter('<TH align="right" valign="top">Année</TH>', Page));
  119.   SetField(fieldCountry, TwoLinesAfter('<TH align="right" valign="top">Nationalité</TH>', Page));
  120.   SetField(fieldCategory, TwoLinesAfter('<TH align="right" valign="top">Genre</TH>', Page));
  121.   Value := TwoLinesAfter('<TH align="right" valign="top">Durée</TH>', Page);
  122.   BeginPos := Pos('H', Value);
  123.   IntValue := (StrToInt(Copy(Value, 1, BeginPos - 1), 0) * 60) + (StrToInt(Copy(Value, BeginPos + 1, Length(Value)), 0));
  124.   SetField(fieldLength, IntToStr(IntValue));
  125.   SetField(fieldActors, TwoLinesAfter('<TH align="right" valign="top">Acteurs principaux</TH>', Page));
  126.   SetField(fieldProducer, TwoLinesAfter('<TH align="right" valign="top">Distribution</TH>', Page));
  127.   if LargePicture then
  128.   begin
  129.     LineNr := FindLine('<A href="/getjpg.html/', Page, 0);
  130.     if LineNr > -1 then
  131.     begin
  132.       Line := Page.GetString(LineNr);
  133.       BeginPos := Pos('/getjpg.html/', Line);
  134.       Value := Copy(Line, BeginPos, Length(Line));
  135.       Delete(Value, Length(Value)-1, 1);
  136.       GetPicture('http://www.moviecovers.com/' + Value, False);
  137.     end;
  138.   end
  139.   else
  140.   begin
  141.     LineNr := FindLine('hspace=20 vspace=4 src="http://www.moviecovers.com/DATA/thumbs', Page, 0);
  142.     if LineNr > -1 then
  143.     begin
  144.       Line := Page.GetString(LineNr);
  145.       BeginPos := Pos('http://', Line);
  146.       EndPos := Pos('"></A>', Line);
  147.       Value := Copy(Line, BeginPos, EndPos - BeginPos);
  148.       GetPicture(Value, False);
  149.     end;
  150.   end;
  151.   Page.Free;
  152.   DisplayResults;
  153. end;
  154.  
  155. procedure GetLargePicture(Address: string);
  156.  
  157. begin
  158.  
  159. end;
  160.  
  161. begin
  162.   if CheckVersion(3,4,2) then
  163.   begin
  164.     MovieName := GetField(fieldTranslatedTitle);
  165.     if MovieName = '' then
  166.       MovieName := GetField(fieldOriginalTitle);
  167.     if Input('MovieCovers import', 'Entrez le titre du film :', MovieName) then
  168.     begin
  169.       AnalyzePage('http://www.moviecovers.com/multicrit.html?titre=' + UrlEncode(MovieName) + '&slow=1&listes=1');
  170.     end;
  171.   end else
  172.     ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.2)');
  173. end.
  174.